#ifndef __PASSTHROUGH_PIPE_CONN__
#define __PASSTHROUGH_PIPE_CONN__

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include <Shlobj.h>

#define PIPE_BUFFER_LEN 0x100000 //1M

void pipeConnect(const char *pipeNameFormat, const char *prefix, HANDLE pipe);
HANDLE pipeConnect(const char *pipeNameFormat, const char *suffix);
int pipeWrite(HANDLE hPipe, void *buf, unsigned int size);
int pipeWrite(HANDLE hPipe, void *buf, unsigned int *size, OVERLAPPED *ol);
int pipeRead(HANDLE hPipe, void *buf, unsigned int len);
int pipeRead(HANDLE hPipe, void *buf, unsigned int *len, OVERLAPPED *ol);
void pipeClose(HANDLE hPipe);

//there may be many pipe connections for one virtio device, e.g. opengl device.
//we use table to handle these connections
void InitPipes(HANDLE pipes[], int maxNum);
int TakeOneSlot(HANDLE pipes[], int maxNum, HANDLE hPipe);
void ReturnOneSlot(HANDLE pipes[], int maxNum, int slot);
HANDLE GetPipeHandleAt(HANDLE pipes[], int maxNum, int slot);

#endif
